package com.my.ddd_sample_collections.aggregate_change_tracking.abstract_domain;

import com.my.ddd_sample_collections.aggregate_change_tracking.repository_framework.DomainObject;
import com.my.ddd_sample_collections.aggregate_change_tracking.repository_framework.DomainObjectSupport;
import lombok.Builder;
import lombok.experimental.SuperBuilder;

import java.util.List;
import java.util.Objects;

@SuperBuilder
public class AbstractComplexDO extends DomainObjectSupport {
    private String  foo;

    private AbstractSimpleDO2 simple2;
    
    private final List<? extends DomainObject> items= new MyArrayList<>(this, "items");
    
    public String getFoo() {
        return foo;
    }

    protected void setFoo(String foo) {
        if (!Objects.deepEquals(this.foo, foo)) {
            track(this, this.foo, "foo", foo);
        }
        this.foo = foo;
    }
    
    public List<? extends DomainObject> getItems() {
        return items;
    }
    
//    TODO 使用lombok builder的时候，默认会忽略字段的初始化，如果要要不忽略，需要加上 @BUilder.default，但是加上之后不能引用this，为了可以不被忽略还可以改为final，但是就不能有setter了
//    protected void setItems(MyArrayList<? extends DomainObject> items) {
//        if (!Objects.deepEquals(this.items, items)) {
//            track(this, this.items, "items", items);
//        }
//        this.items = items;
//    }
    
    public AbstractSimpleDO2 getSimple2() {
        return simple2;
    }

    protected void setSimple2(AbstractSimpleDO2 simple2) {
        if (!Objects.deepEquals(this.simple2, simple2)) {
            track(this, this.simple2, "simple2", simple2);
        }
        this.simple2 = simple2;
    }
}
